package com.zdj;

import java.util.HashMap;
import java.util.Scanner;

/**
 * @author zhangdj
 * @date 2021-10-14 16:35:57
 */
public class Tlv {

    public static void main(String[] args) {
        tlv();
    }


    public static void tlv() {
        Scanner scanner = new Scanner(System.in);
        String tag = scanner.nextLine();
        String dataStream = scanner.nextLine();
        if (dataStream == null || dataStream.length() <= 0) {
            return;
        }
        // 切分数据
        String[] array = dataStream.split(" ");
        // 保存所有的信元
        HashMap<String, TLV> hashMap = new HashMap<>();

        TLV tlv = new TLV();
        for (int i = 0; i < array.length; ) {
            if (i == 0 || tlv.getTag() == null) {
                tlv.setTag(array[i]);
            }
            if (tlv.getTag() != null && tlv.getTag().length() > 0) {
                String translate = translate(array[i + 1]);
                String translate1 = translate(array[i + 2]);
                // 信元长度
                int length = Integer.parseInt(translate) + Integer.parseInt(translate1);
                tlv.setLength(length);
                // 取相应的长度作为数据 i+ 3 -> i + 3 + length
                StringBuilder data = new StringBuilder();
                int j = i + 3;
                while (j < i + 3 + length) {
                    if (j >= array.length) {
                        break;
                    }
                    data.append(array[j]).append(" ");
                    j++;
                }
                tlv.setData(data.toString());
                hashMap.put(tlv.getTag(), tlv);
                tlv = new TLV();
                i = i + 3 + length;
            }
        }
        TLV tlv1 = hashMap.get(tag);
        System.out.println(tlv1.getData());
    }

    /**
     * 16进制转10进制
     *
     * @param s 16进制字符串
     * @return 10进制
     */
    public static String translate(String s) {
        switch (s) {
            case "0A":
                return "11";
            case "0B":
                return "12";
            case "0C":
                return "13";
            case "0D":
                return "14";
            case "0E":
                return "15";
            case "0F":
                return "16";
            default:
                return s;
        }
    }

    static class TLV {
        private String tag;

        private Integer length;

        private String data;

        public void setAllNull() {
            this.tag = null;
            this.length = null;
            this.data = null;
        }

        public String getTag() {
            return tag;
        }

        public void setTag(String tag) {
            this.tag = tag;
        }

        public Integer getLength() {
            return length;
        }

        public void setLength(Integer length) {
            this.length = length;
        }

        public String getData() {
            return data;
        }

        public void setData(String data) {
            this.data = data;
        }
    }
}
